
public class BinaryTree {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		TreeNode root = new TreeNode(new TreeNode(new TreeNode("D"), "B", null), 
				"A", new TreeNode(new TreeNode(null, "E", new TreeNode("G")), 
						"C", new TreeNode(new TreeNode("H"), "F", new TreeNode("I"))));
		preScan(root);
		System.out.println();
		midScan(root);
		System.out.println();
		afterScan(root);
		System.out.println();

	}
	
	public static void preScan(TreeNode node){
		if(node == null)
			return;
		System.out.print(node.element + "\t");
		preScan(node.left);
		preScan(node.right);
		return;
	}
	
	public static void midScan(TreeNode node){
		if(node == null)
			return;
		midScan(node.left);
		System.out.print(node.element + "\t");
		midScan(node.right);
		return;
	}
	
	public static void afterScan(TreeNode node){
		if(node == null)
			return;
		afterScan(node.left);
		afterScan(node.right);
		System.out.print(node.element + "\t");
		return;
	}
	
}


class TreeNode{
	
	public TreeNode(TreeNode left, String element, TreeNode right) {
		this.element = element;
		this.left = left;
		this.right = right;
	}
	
	public TreeNode(String element){
		this.element = element;
		right = left = null;
	}
	
	String element;
	TreeNode left;
	TreeNode right;
}